package com.hengtongxing.hejiayun.homepage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hengtongxing.hejiayun.R;
import com.hengtongxing.hejiayun.bean.GoodsListBean;
import com.hengtongxing.hejiayun.bean.RefundRecordBean;
import com.hengtongxing.hejiayun.utils.GlideUtils;
import com.hengtongxing.hejiayun.utils.NumberFormatUtils;
import com.makeramen.roundedimageview.RoundedImageView;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 退款记录
 */
public class RefundRecordAdapter extends RecyclerView.Adapter<RefundRecordAdapter.ViewHolder> {

    private List<RefundRecordBean.Data> listsBeans;
    private Context context;
    private onCallBackListener onCallBackListener;

    public void setOnCallBackListener(onCallBackListener onCallBackListener) {
        this.onCallBackListener = onCallBackListener;
    }

    public RefundRecordAdapter(List<RefundRecordBean.Data> listsBeans) {
        this.listsBeans = listsBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_refund_record_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        RefundRecordBean.Data dataBean = listsBeans.get(position);

        holder.tv_order_goods_id.setText("商品订单id："+dataBean.getOrder_goods_id());
        holder.tv_shop_order_id.setText("订单id："+dataBean.getShop_order_id());
        int goods_status = dataBean.getGoods_status();
        int status = dataBean.getStatus();


        if (goods_status==1){
            holder.tv_goods_status.setText("货物状态：未收到货");
        }else {
            holder.tv_goods_status.setText("货物状态：已收到货");
        }

        holder.tv_remark.setText("退款原因："+dataBean.getRemark());
        holder.tv_refund_amount.setText("退款金额："+dataBean.getRefund_amount()/100+"元");

        if (status==1){
            holder.tv_status.setText("退款状态：已申请");
        }else if (status==2){
            holder.tv_status.setText("退款状态：商家已同意");
        }else if (status==3){
            holder.tv_status.setText("退款状态：商家拒绝");
        }else if (status==4){
            holder.tv_status.setText("退款状态：退款失败");
        }else if (status==5){
            holder.tv_status.setText("退款状态：退款成功");
        }else {
            holder.tv_status.setText("退款状态：未知");
        }
        holder.tv_depict.setText("补充描述："+dataBean.getDepict());
        holder.tv_create_date.setText("创建时间："+dataBean.getCreate_date());


        holder.itemView.setOnClickListener(v -> {
            onCallBackListener.onCallBack(position);
        });
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_order_goods_id)
        TextView tv_order_goods_id;
        @BindView(R.id.tv_shop_order_id)
        TextView tv_shop_order_id;
        @BindView(R.id.tv_goods_status)
        TextView tv_goods_status;
        @BindView(R.id.tv_remark)
        TextView tv_remark;
        @BindView(R.id.tv_refund_amount)
        TextView tv_refund_amount;
        @BindView(R.id.tv_status)
        TextView tv_status;
        @BindView(R.id.tv_depict)
        TextView tv_depict;
        @BindView(R.id.tv_create_date)
        TextView tv_create_date;



        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface onCallBackListener {
        void onCallBack(int position);
    }
}
